<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //作业一 创建一个电脑对象，该对象有颜色，重量，型号，品牌 可看电影 打游戏
        function Computer(color,weight,brand){
            this.color = color;
            this.weight = weight;
            this.brand = brand;
            this.effect = function(can){
                console.log(can);
            }
        }
        var dn = new Computer('白色','300g','华为')
        console.log(dn.color);
        dn.effect('唱歌'+'\t'+'看电影'+'\t '+'打游戏'+'\t '+'码代码');
        var pg = new Computer('黄色','400','苹果');
        console.log(pg.brand);

        //作业二 创建一个按钮对象，该对象需要包含宽高背景颜色和点击行为

        function Button(width,height,backgroundColor){
            this.width = width;
            this.height = height;
            this.backgroundColor = backgroundColor;
            this.onclick = function(can){
                console.log(can);
            }
        }
        let btn = new Button('宽'+'300', '高'+'400','背景颜色'+'yellow');
        console.log(btn.backgroundColor);
        btn.onclick('点击之后看我看我！');

        //创建一个车的对象，该对象要有重量，颜色牌子可以载人，拉货
        function Car(width, color, brand){
            this.width = width;
            this.color = color;
            this.brand = brand
            this.cl = function(can){
                console.log(can);
            }
        }
        let ft = new Car(300,'blue','福特');
        console.log(ft.brand);
        ft.cl(ft.brand+'可以'+'拉货'+'载人');

        //写一个函数实现可以反转任意数组；
        function reverse(arr){
           let newArr = [];
        //    debugger
            for(var i = arr.length-1; i>=0; i--){
                newArr[newArr.length] = arr[i];
            }
            return newArr
        }
        var arr = reverse([23,4,34,22,5,2,9])
        console.log(arr);
        

        //编写函数实现任意一组数组按从大到小排列
        function sort(arr){
            for(var i = 0; i<arr.length;i++){
                for(var j = 0; j<arr.length-1;j++){
                    if(arr[j] > arr[j+1]){
                        temp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = temp;
                    }
                }
            }
            return arr
        }
        var arr = sort([3,33,2,1,56,3,654])
        console.log(arr);

        //做一个简易计算机
         function calculation(){
             var num = prompt('简易计算机'+'\n'+'1.加法计算'+
             '\n'+'2.减法计算'+'\n'+'3.乘法运算'+'\n'+'4.除法运算'+'\n'+'5.退出')
             if(num != 5){
                 console.log(num);
                var one = parseFloat(prompt('请输入第一个值'));
                var two = parseFloat(prompt('请输入第二个值'));
            }
            var sum = 0;
            //  debugger
             switch(num){
                case '1':
                    sum = one+two;
                    alert(one+'+'+ two +'='+sum);
                    calculation()
                break;
                case '2':
                    sum = one-two;
                    alert(one+'-'+ two +'='+sum);
                    calculation()
                break;
                case '3':
                    sum = one*two;
                    alert(one+'*'+ two +'='+sum);
                    calculation()
                break;
                case '4':
                    sum = one/two;
                    alert(one+'/'+ two +'='+sum);
                    calculation()
                break;
                default:
                    alert('正在退出')
             }
             return num
         }
         calculation()
    </script>
</body>
</html>